package com.bobi.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bobi.entity.Staff;
import com.bobi.enums.ResultCode;
import com.bobi.mapper.StaffMapper;
import com.bobi.service.StaffService;
import com.bobi.utils.ResultUtil;
import com.bobi.utils.Token;
import org.springframework.stereotype.Service;

/**
 * @author wenyuan
 * @version 1.0
 * @date 2023/7/4
 * @since 8
 */
@Service
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements StaffService {
    @Override
    public Token login(String username, String password) {
        Staff staff = this.findByUsername(username);

        if (staff == null || staff.getLeaveTime() == null ) {
            // throw new ServiceException(ResultCode.USER_PASSWORD_ERROR);
            // TODO 待写异常抛出
            // return ResultUtil.error()
        }
        // if (!new BCryptPasswordEncoder().matches(password, adminUser.getPassword())) {
        //     throw new ServiceException(ResultCode.USER_PASSWORD_ERROR);
        // }
        // try {
        //     return managerTokenGenerate.createToken(adminUser, false);
        // } catch (Exception e) {
        //     log.error("管理员登录错误", e);
        // }
        return null;
    }


    public Staff findByUsername(String username) {

        Staff staff = getOne(new LambdaQueryWrapper<Staff>().eq(Staff::getName, username));

        if (staff == null) {
            return null;
        }
        return staff;
    }

}